<template>
	<view class="B1">
		<text style="font-size: 60rpx;color: gray;">组件B</text>
		<view class="B2">
			组件A传值:
			<text>{{result}}</text>
		</view>
		<view>
			<view class="B2">
				<text>回传值输入:</text><input type="text" v-model="callBack" style="color: firebrick;" />
			</view>
			<button @click="sendOut()" style="width: 500rpx; height: 100rpx;">回传</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "SonB",
		data() {
			return {
				result: '',
				callBack: ''
			};
		},
		methods: {
			sendOut() {
				if (this.callBack.trim()) {
					console.warn("--SonB--" + this.callBack);
					this.$emit('cb', this.callBack);
					this.callBack = '';
				}
			}
		},
		created() {
			uni.$on('getIntent', (msg) => {
				console.error("--SonB--" + msg);
				this.result = msg;
			});
		},
		beforeDestroy() {
			uni.$off('getIntent');
		}
	}
</script>

<style>
	.B1 {
		background-color: greenyellow;
	}

	.B2 {
		display: flex;
	}
</style>